import { defineStore } from 'pinia'
// 导入axios
import request from '@/utils/request'
import { BannerItem, IApiRes, GoodItem, HotGoods, Brand, HomeProduct, Special } from '@/types/data'
// 应为只有汉字，所以给它添加一个id属性
export default defineStore('home', {
    state: () => ({
        // 轮播图数据
        bannerList: [] as BannerItem[],
        // 新鲜好物数据
        newGoodList: [] as GoodItem[],
        // 人气推荐数据
        hotGoodList: [] as HotGoods[],
        // 热门品牌数据
        brandList: [] as Brand[],
        // 首页商品列表推荐
        productList: [] as HomeProduct[],
        // 最新专题 
        specialList: [] as Special[]
    }),
    actions: {
        // 获取轮播图数据
        async getBannerList() {
            const { data: { result } } = await request.get<IApiRes<BannerItem[]>>('/home/banner')
            this.bannerList = result
        },

        // 获取新鲜好物数据
        async getNewList() {
            const { data: { result } } = await request.get<IApiRes<GoodItem[]>>('/home/new')
            this.newGoodList = result
        },

        // 获取人气推荐数据
        async getHotList() {
            const { data: { result } } = await request.get<IApiRes<HotGoods[]>>('/home/hot')
            this.hotGoodList = result
        },

        // 获取热门品牌数据
        async getBrandList() {
            const { data: { result } } = await request.get<IApiRes<Brand[]>>('/home/brand')
            this.brandList = result
        },

        // 首页商品列表推荐数据
        async getProductList() {
            const { data: { result } } = await request.get<IApiRes<HomeProduct[]>>('/home/goods')
            this.productList = result
        },

        // 获取最新专题数据
        async getSpecialList() {
            const { data: { result } } = await request.get<IApiRes<Special[]>>('/home/special')
            this.specialList = result
            console.log(result)
        }
    },
    getters: {}
})